package com.zhongli.devplatform.utils;

import java.util.Random;

/** 
 * @author  wyz
 * @date 创建时间：2020年6月11日 下午4:20:40
 * @Description: TODO(这里用一句话描述这个类的作用)  
 * @version 1.0
*/
public class StringUtils extends org.apache.commons.lang3.StringUtils {
	/**
     * StringUtils工具类方法
     * 获取一定长度的随机字符串，范围0-9，a-z
     * @param length：指定字符串长度
     * @return 一定长度的随机字符串
     */
    public static String getRandomStringByLength(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 获取纯数字验证码
     */
    public static String getVerifyCode(int length) {
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(StringUtils.getVerifyCode(6));
    }
}
